﻿package mortal.game.view.friend
{
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class FriendApplyWin extends SmallWindow
    {
        private var _applyerList:GTileList;
        private var _refuseAllBtn:GButton;
        private var _recieveAllBtn:GButton;
        private static var _instance:FriendApplyWin;

        public function FriendApplyWin(param1:ILayer = null)
        {
            super(param1);
            if (_instance)
            {
                throw new Error("FriendApplyWin 单例");
            }
            this.init();
            this.layer = LayerManager.windowLayer;
            return;
        }// end function

        private function init() : void
        {
            setSize(320, 230);
            title = Language.getString(41214);
            this.isHideDispose = false;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._applyerList = UIFactory.tileList(8, 35, 312 + 10, 64 * 5, this);
            this._applyerList.columnWidth = 292 + 10;
            this._applyerList.rowHeight = 63;
            this._applyerList.setStyle("skin", new Bitmap());
            this._applyerList.setStyle("cellRenderer", FriendApplyCellRenderer);
            this.addChild(this._applyerList);
            this._refuseAllBtn = UIFactory.gButton(Language.getString(41215), 176, 194, 79, 23, this);
            this._recieveAllBtn = UIFactory.gButton(Language.getString(41216), 78, 194, 79, 23, this);
            this._refuseAllBtn.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this._recieveAllBtn.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            Dispatcher.addEventListener(EventName.FriendApplyListUpdate, this.onApplyListUpdate);
            return;
        }// end function

        override protected function configParams() : void
        {
            super.configParams();
            paddingBottom = 48;
            return;
        }// end function

        override protected function setWindowCenter() : void
        {
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show();
            this.updateAll();
            return;
        }// end function

        public function updateAll() : void
        {
            if (!isHide)
            {
                this.updateList();
                this.updateWinSize();
            }
            return;
        }// end function

        private function updateWinSize() : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_1:* = this._applyerList.rowHeight;
            var _loc_2:* = Cache.instance.friend.applyList.length;
            if (_loc_2 >= 2)
            {
                _loc_3 = _loc_2 > 5 ? (5) : (_loc_2);
                _loc_4 = _loc_3 * _loc_1;
                this.height = 96 + _loc_4;
                this.width = 320;
                paddingBottom = 48;
                this._recieveAllBtn.y = this.height - 40;
                this._refuseAllBtn.y = this.height - 40;
            }
            else
            {
                this.width = 320;
                this.height = 230;
                this._recieveAllBtn.y = this.height - 40;
                this._refuseAllBtn.y = this.height - 40;
            }
            return;
        }// end function

        private function updateList() : void
        {
            var _loc_1:* = Cache.instance.friend.applyList;
            var _loc_2:* = new DataProvider();
            _loc_2.addItems(_loc_1);
            this._applyerList.dataProvider = _loc_2;
            this._applyerList.drawNow();
            return;
        }// end function

        private function onApplyListUpdate(event:DataEvent) : void
        {
            this.updateAll();
            return;
        }// end function

        private function onClickHandler(event:MouseEvent) : void
        {
            var _loc_2:int = 0;
            var _loc_5:SMiniPlayer = null;
            var _loc_3:Object = {};
            var _loc_4:Array = [];
            if (event.target == this._recieveAllBtn)
            {
                _loc_2 = EFriendReplyResult._EFriendReplyResultAccept;
            }
            else
            {
                _loc_2 = EFriendReplyResult._EFriendReplyResultReject;
            }
            for each (_loc_5 in Cache.instance.friend.applyList)
            {
                
                _loc_4.push(_loc_5.entityId.id);
            }
            _loc_3["result"] = _loc_2;
            _loc_3["playerId"] = _loc_4;
            Dispatcher.dispatchEvent(new DataEvent(EventName.FriendReply, _loc_3));
            return;
        }// end function

        override protected function closeBtnClickHandler(event:MouseEvent) : void
        {
            var _loc_2:int = 0;
            var _loc_5:SMiniPlayer = null;
            super.closeBtnClickHandler(event);
            var _loc_3:Object = {};
            var _loc_4:Array = [];
            _loc_2 = EFriendReplyResult._EFriendReplyResultReject;
            for each (_loc_5 in Cache.instance.friend.applyList)
            {
                
                _loc_4.push(_loc_5.entityId.id);
            }
            _loc_3["result"] = _loc_2;
            _loc_3["playerId"] = _loc_4;
            Dispatcher.dispatchEvent(new DataEvent(EventName.FriendReply, _loc_3));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._applyerList.dispose(param1);
            this._refuseAllBtn.dispose(param1);
            this._recieveAllBtn.dispose(param1);
            this._applyerList = null;
            this._refuseAllBtn = null;
            this._recieveAllBtn = null;
            Cache.instance.friend.clearApplyList();
            return;
        }// end function

        public static function get instance() : FriendApplyWin
        {
            if (!_instance)
            {
                _instance = new FriendApplyWin;
            }
            return _instance;
        }// end function

    }
}
